// ml:run = $bin < input
#include <cstdio>
#include <algorithm>
#include <cstring>

template <class T>
void scan(T & a)
{
	a = 0;
	bool flag = false;
	char ch = std::getchar();
	if (ch == '-')
		flag = true;
	else if (ch >= '0' && ch <= '9')
		a = ch - '0';

	while ((ch = std::getchar()) >= '0' && ch <= '9')
		a = a * 10 + ch - '0';
	if (flag) a = -a;
}

int const maxn = 3000007;
int last[maxn];
int sum[maxn];
int r[maxn];
int ans[maxn];
int n, k, q;

int main()
{
    int T; scan(T);
    while (T--) {
        scan(n); scan(k); scan(q);
        memset(sum, 0, sizeof(sum));
        memset(last, 0, sizeof(last));
        int maxr = 0;
        for (int i = 1; i <= n; i++) {
            if ((i - 1) % k == 0) r[i] = 1;
            else r[i] = r[i - (i - 2) / k - 1] + 1;
            printf("%d ", r[i]);
            sum[r[i]]++;
            maxr = std::max(maxr, r[i]);
        }
        printf("\n");

        for (int i = 2; i <= maxr; i++)
            sum[i] = sum[i - 1] + sum[i];
        for (int i = 1; i <= n; i++) {
            ans[i] = sum[r[i] - 1] + last[r[i]]++ + 1;
        }
        for (int i = 0, x; i < q; i++) {
            scan(x);
            std::printf("%d ", ans[x]);
        }
        std::printf("\n");
    }
}

